<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="产品附加属性" prop="productId">
									<el-input v-model="form.productId" placeholder="请输入产品附加属性" clearable></el-input>
								</el-form-item>
								<el-form-item label="客户评论 总数量" prop="commentCount">
									<el-input v-model="form.commentCount" placeholder="请输入客户评论 总数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="好评率1-100" prop="commentHp">
									<el-input v-model="form.commentHp" placeholder="请输入好评率1-100" clearable></el-input>
								</el-form-item>
								<el-form-item label="好评数量" prop="commentHpsl">
									<el-input v-model="form.commentHpsl" placeholder="请输入好评数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="中差评数量" prop="commentZcsl">
									<el-input v-model="form.commentZcsl" placeholder="请输入中差评数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="总星数量" prop="commentXjzl">
									<el-input v-model="form.commentXjzl" placeholder="请输入总星数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="浏览人数" prop="lookCount">
									<el-input v-model="form.lookCount" placeholder="请输入浏览人数" clearable></el-input>
								</el-form-item>
								<el-form-item label="收藏人数" prop="collectionCount">
									<el-input v-model="form.collectionCount" placeholder="请输入收藏人数" clearable></el-input>
								</el-form-item>
								<el-form-item label="称赞人数" prop="tagCount">
									<el-input v-model="form.tagCount" placeholder="请输入称赞人数" clearable></el-input>
								</el-form-item>
								<el-form-item label="销售数量" prop="saleCount">
									<el-input v-model="form.saleCount" placeholder="请输入销售数量" clearable></el-input>
								</el-form-item>
								<el-form-item label="库存数量 -9不限库存" prop="stockQty">
									<el-input v-model="form.stockQty" placeholder="请输入库存数量 -9不限库存" clearable></el-input>
								</el-form-item>
								<el-form-item label="物流重量(Kg)" prop="logisWeight">
									<el-input v-model="form.logisWeight" placeholder="请输入物流重量(Kg)" clearable></el-input>
								</el-form-item>
								<el-form-item label="物流体积(m3)" prop="logisVolume">
									<el-input v-model="form.logisVolume" placeholder="请输入物流体积(m3)" clearable></el-input>
								</el-form-item>
								<el-form-item label="快递模板公司 0包邮 <0系统模板id的负数" prop="logisModelId">
									<el-input v-model="form.logisModelId" placeholder="请输入快递模板公司 0包邮 <0系统模板id的负数" clearable></el-input>
								</el-form-item>
								<el-form-item label="供应商id" prop="providerId">
									<el-input v-model="form.providerId" placeholder="请输入供应商id" clearable></el-input>
								</el-form-item>
								<el-form-item label="产品页面模板" prop="templatePath">
									<el-input v-model="form.templatePath" placeholder="请输入产品页面模板" clearable></el-input>
								</el-form-item>
								<el-form-item label="创建时间" prop="createTime">
									<el-input v-model="form.createTime" placeholder="请输入创建时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="发布时间" prop="publishTime">
									<el-input v-model="form.publishTime" placeholder="请输入发布时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="计划下架时间" prop="planEndTime">
									<el-input v-model="form.planEndTime" placeholder="请输入计划下架时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="计划上架时间" prop="planStartTime">
									<el-input v-model="form.planStartTime" placeholder="请输入计划上架时间" clearable></el-input>
								</el-form-item>
								<el-form-item label="有无发票 1有 0无" prop="invoice">
									<el-input v-model="form.invoice" placeholder="请输入有无发票 1有 0无" clearable></el-input>
								</el-form-item>
								<el-form-item label="有无保修 1有 0无" prop="guarantee">
									<el-input v-model="form.guarantee" placeholder="请输入有无保修 1有 0无" clearable></el-input>
								</el-form-item>
								<el-form-item label="联系人" prop="linkMan">
									<el-input v-model="form.linkMan" placeholder="请输入联系人" clearable></el-input>
								</el-form-item>
								<el-form-item label="联系电话" prop="linkTel">
									<el-input v-model="form.linkTel" placeholder="请输入联系电话" clearable></el-input>
								</el-form-item>
								<el-form-item label="联系地址" prop="linkAddress">
									<el-input v-model="form.linkAddress" placeholder="请输入联系地址" clearable></el-input>
								</el-form-item>
								<el-form-item label="经度" prop="longitude">
									<el-input v-model="form.longitude" placeholder="请输入经度" clearable></el-input>
								</el-form-item>
								<el-form-item label="纬度" prop="latitude">
									<el-input v-model="form.latitude" placeholder="请输入纬度" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	import productAPI from '@/api/product/productDetails';
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: ''
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					productId: "",
					commentCount: "",
					commentHp: "",
					commentHpsl: "",
					commentZcsl: "",
					commentXjzl: "",
					lookCount: "",
					collectionCount: "",
					tagCount: "",
					saleCount: "",
					stockQty: "",
					logisWeight: "",
					logisVolume: "",
					logisModelId: "",
					providerId: "",
					templatePath: "",
					createTime: "",
					publishTime: "",
					planEndTime: "",
					planStartTime: "",
					invoice: "",
					guarantee: "",
					linkMan: "",
					linkTel: "",
					linkAddress: "",
					longitude: "",
					latitude: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await productAPI.productDetails.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.productId = data.productId;
				this.form.commentCount = data.commentCount;
				this.form.commentHp = data.commentHp;
				this.form.commentHpsl = data.commentHpsl;
				this.form.commentZcsl = data.commentZcsl;
				this.form.commentXjzl = data.commentXjzl;
				this.form.lookCount = data.lookCount;
				this.form.collectionCount = data.collectionCount;
				this.form.tagCount = data.tagCount;
				this.form.saleCount = data.saleCount;
				this.form.stockQty = data.stockQty;
				this.form.logisWeight = data.logisWeight;
				this.form.logisVolume = data.logisVolume;
				this.form.logisModelId = data.logisModelId;
				this.form.providerId = data.providerId;
				this.form.templatePath = data.templatePath;
				this.form.createTime = data.createTime;
				this.form.publishTime = data.publishTime;
				this.form.planEndTime = data.planEndTime;
				this.form.planStartTime = data.planStartTime;
				this.form.invoice = data.invoice;
				this.form.guarantee = data.guarantee;
				this.form.linkMan = data.linkMan;
				this.form.linkTel = data.linkTel;
				this.form.linkAddress = data.linkAddress;
				this.form.longitude = data.longitude;
				this.form.latitude = data.latitude;
			}
		}
	}
</script>
<style>
</style>
